﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using MenusHunter.WinRT.Core.ViewModels;
using MenusHunter.WinRT.Views;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.ApplicationSettings;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236

namespace MenusHunter.WinRT.UserControls
{
    public sealed partial class AccountSettings : UserControl
    {
        private AccountSettingsViewModel _viewModel;

        public AccountSettings()
        {
            this.InitializeComponent();
            _viewModel = DataContext as AccountSettingsViewModel;
            if(_viewModel!=null)
            {
                _viewModel.PropertyChanged+=_viewModel_PropertyChanged;
            }
        }

        private void _viewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if(e.PropertyName.Equals("LogoutSuccess"))
            {
                var frame = Window.Current.Content as Frame;
                if (frame != null) frame.Navigate(typeof (Login));
            }
        }

        private void MySettingsBackClicked(object sender, RoutedEventArgs e)
        {
            if (this.Parent.GetType() == typeof(Popup))
            {
                ((Popup)this.Parent).IsOpen = false;
            }
            SettingsPane.Show();
        }
    }
}
